package com.projectw.common.util;

import com.projectw.common.result.ResultMapper;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;


/**
 * Created by Peter_Wang on 2018/8/20.
 */
@ConfigurationProperties
@Component
public final class SystemUtils {

    protected static HttpHeaders headers = new HttpHeaders();
    static {
        headers.add("Content-Type", "application/json; charset=utf-8");
    }

    public static ResponseEntity<String> returnSuccessMsg(ResultMapper resultMapper){
        if(resultMapper.getData()==null){
            resultMapper.setData(new Object());
        }
        if(resultMapper.getSys()==null){
            resultMapper.setSys(new Object());
        }
        return new ResponseEntity<String>(JSON.toJSONString(resultMapper), headers, HttpStatus.OK);
    }
}
